//
//  WCNewFileTemplate.m
//  WabbitCode
//
//  Created by William Towe on 3/29/09.
//  Copyright 2009 Revolution Software. All rights reserved.
//

#import "WCNewFileTemplate.h"
#import "WCNewFileWindowController.h"


@implementation WCNewFileTemplate
- (void)dealloc {
	[_name release];
	[_templateInfo release];
	[_templateDirectory release];
	[_icon release];
	[super dealloc];
}

- (NSString *)description {
	return [NSString stringWithFormat:@"<%@>, name: %@, templateDirectory: %@, templateInfo: %@", NSStringFromClass([self class]), [self name], [self templateDirectory], [self templateInfo]];
}

@synthesize name=_name,icon=_icon,templateDirectory=_templateDirectory,templateInfo=_templateInfo;

@dynamic fileExtension;
- (NSString *)fileExtension {
	NSString *retval = [_templateInfo objectForKey:kWCNewFileTemplateInfoFileExtensionKey];
	if (!retval)
		return @"asm"; // because I like .asm better than .z80
	return retval;
}

- (NSImage *)icon {
	if (!_icon)
		return [NSImage imageNamed:@"assembly"];
	return _icon;
}

@dynamic shortDescription;
- (NSString *)shortDescription {
	NSString *retval = [_templateInfo objectForKey:kWCNewFileTemplateInfoShortDescriptionKey];
	
	if (!retval)
		return NSLocalizedString(@"No long description provided",@"no long description provided for this project template");
	return retval;
}

@dynamic longDescription;
- (NSString *)longDescription {
	NSString *retval = [_templateInfo objectForKey:kWCNewFileTemplateInfoLongDescriptionKey];
	
	if (!retval)
		return NSLocalizedString(@"No long description provided",@"no long description provided for this project template");
	return retval;
}

- (id)initWithName:(NSString *)name templateInfo:(NSDictionary *)templateInfo templateDirectory:(NSString *)templateDirectory; {
	if (!(self = [super init]))
		return nil;
	
	_name = [name copy];
	_templateInfo = [templateInfo retain];
	_templateDirectory = [templateDirectory copy];
	_icon = [[[NSWorkspace sharedWorkspace] iconForFileType:[_templateInfo objectForKey:kWCNewFileTemplateInfoFileExtensionKey]] retain];
	
	return self;
}

+ (WCNewFileTemplate *)newFileTemplateWithName:(NSString *)name templateInfo:(NSDictionary *)templateInfo templateDirectory:(NSString *)templateDirectory; {
	return [[[[self class] alloc] initWithName:name templateInfo:templateInfo templateDirectory:templateDirectory] autorelease];
}
@end
